﻿package domino 
{
	import Box2D.Common.Math.b2Vec2;
	import flash.display.Bitmap;
	import flash.display.DisplayObjectContainer;
	import flash.display.MovieClip;
	import flash.geom.Point;
	import flash.display.Sprite;
	 import flash.geom.Vector3D;
	
	import Box2D.Dynamics.*;
	import Box2D.Collision.*;
	import Box2D.Collision.Shapes.*;
	
	/**
	 * ...
	 * @author ...
	 */
	public class actorTriangle extends actor
	{
		   private var final_body:b2Body;
		   private var the_body:b2BodyDef;
		   private var the_box:b2PolygonDef;
			
		   public var stat:Number;
		   public var dominSprite:Sprite ;
		   public var scaleX:Number, scaleY:Number;
		   public var density:Number, angV:Number;
		   public var shapes:Array = [];
		   public var shapeIndex:int = -1;
		   
		   public var isSensor:int;
		 //  [Embed(source="tri.png")]
          // public var triPNG:Class;
		   
			//public var restitution;
		public function actorTriangle(_world:b2World,parent:DisplayObjectContainer,dominPosition:Point,_rot:Number,_density:Number,_friction:Number,_scaleX:Number,_scaleY:Number,_restitution:Number,_isSensor:int) 
		{
			//create costume
		    dominSprite = new tri();
            dominSprite.scaleX = _scaleX;
			dominSprite.scaleY = _scaleY;
			scaleX = _scaleX;
			scaleY = _scaleY;
			dominSprite.x = dominPosition.x;
			dominSprite.y = dominPosition.y;
			parent.addChild(dominSprite);
			 var i:int;
			//create body
			the_body = new b2BodyDef();
			the_body.position.Set(dominSprite.x / 30, dominSprite.y / 30);
			the_body.angle = _rot * Math.PI / 180;

			isSensor = _isSensor;
			density = _density;
			angV = 0;
			final_body = _world.CreateBody(the_body);
			//1
			
			the_box = new b2PolygonDef();	
			the_box.vertexCount = 3;
	        the_box.vertices[0].Set(0, 0);
			the_box.vertices[1].Set(dominSprite.width/30,dominSprite.height/30);
			the_box.vertices[2].Set(0,dominSprite.height/30);
			
			the_box.userData = 0;
	
			the_box.density = _density;
		    the_box.restitution = _restitution;
			the_box.friction = _friction;	
			the_box.isSensor = Boolean(isSensor);
		
			final_body.CreateShape(the_box);
	
		    final_body.SetXForm(new b2Vec2(final_body.GetPosition().x,final_body.GetPosition().y), _rot * Math.PI/180);
			final_body.SetMassFromShapes();
		
			
			super(final_body, dominSprite);
			setMovie(_density);
		}
	
			
		private function setMovie(s:Number):void {
			if(s==0)
			 MovieClip(_costume).gotoAndStop(2);
			else
			 MovieClip(_costume).gotoAndStop(1);
			 
			}
			///////////////////////////////////
	public function getData():Array {
		var data:Array = new Array();
		data.push(_costume.x);
		data.push(_costume.y);
		data.push(dominSprite.scaleX);
		data.push(dominSprite.scaleY);
		data.push(_body.GetShapeList().GetFriction());
		data.push(_body.GetShapeList().m_density);
		data.push(_body.GetAngle()*180/Math.PI);
		data.push(_body.GetShapeList().GetRestitution());
		data.push(0);
		
		return data;
	 }
	 
	
	}

}